
package Presentacion.notas;

import clases.notas.Parcial;
import clases.notas.Curso;
import clases.notas.Excel;
import clases.notas.Notas;
import global.Iconos;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;

public class frmasistencias extends javax.swing.JDialog {
    
    private Iconos ico = new Iconos();
    Curso c = new Curso();
    DefaultTableModel modelo;
    Parcial objparcial;

    public frmasistencias(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(this);
        this.setTitle("IMPORTADOR DE ASISTENCIA");
        this.iconos();
        this.generarModelo();
        c.listarCursoActivoCombo(cbocurso);
        objparcial = new Parcial();
        objparcial.llenarQuimestre(cboquimestre);
        objparcial.llenarParcial(cboparcial);
    }
        private void iconos() {
        btnnuevo.setIcon(ico.getNuevo());
        //  btnnuevo.setText("");
        btnguardar.setIcon(ico.getGuardar());
        // btnguardar.setText("");
        btnsalir.setIcon(ico.getSalir());
        //    btnsalir.setText("");
    }
        private void generarModelo() {
        modelo = new DefaultTableModel();
        modelo.addColumn("Cedula");
        modelo.addColumn("No.");
        modelo.addColumn("ALUMNO");
        modelo.addColumn("ATRASOS");
        modelo.addColumn("F. JUSTIFICADAS");
        modelo.addColumn("F. INJUSTIFICADAS");
        modelo.addColumn("CORPOTAMIENTO");
        modelo.addColumn("EQUIVALENCIA");
        this.formatearTabla();



    }
           private void formatearTabla() {
        tblasistencias.getColumnModel().getColumn(0).setMaxWidth(0);
        tblasistencias.getColumnModel().getColumn(0).setMinWidth(0);
        tblasistencias.getColumnModel().getColumn(0).setPreferredWidth(0);
          tblasistencias.getColumnModel().getColumn(1).setPreferredWidth(10);
        tblasistencias.getColumnModel().getColumn(2).setPreferredWidth(370);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        btnnuevo = new javax.swing.JButton();
        btnguardar = new javax.swing.JButton();
        btnsalir = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cbocurso = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        cboparcial = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        cboquimestre = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblasistencias = new javax.swing.JTable();
        btnimportar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        btnnuevo.setText("Nuevo");
        btnnuevo.setFocusable(false);
        btnnuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnnuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btnnuevo);

        btnguardar.setText("Guardar");
        btnguardar.setFocusable(false);
        btnguardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnguardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnguardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnguardarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnguardar);

        btnsalir.setText("Salir");
        btnsalir.setFocusable(false);
        btnsalir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnsalir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(btnsalir);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("CURSO");

        cbocurso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbocurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbocursoActionPerformed(evt);
            }
        });

        jLabel7.setText("PARCIAL");

        cboparcial.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- SELECCIONE --", "1", "2", "3", "4", "5" }));

        jLabel5.setText("QUIMESTRE");

        cboquimestre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- SELECCIONE --", "1", "2" }));

        tblasistencias.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "cedula", "No.", "ESTUDIANTE", "ATRASOS", "F. JUSTIFICADAS", "F. INJUSTIFICADAS", "COMPORTAMIENTO", "EQUIVALENCIA"
            }
        ));
        jScrollPane1.setViewportView(tblasistencias);

        btnimportar.setText("Importar Excel");
        btnimportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnimportarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(cbocurso, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cboparcial, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(26, 26, 26)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cboquimestre, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 383, Short.MAX_VALUE)
                        .addComponent(btnimportar)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cbocurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(cboparcial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(cboquimestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnimportar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbocursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbocursoActionPerformed
        if (cbocurso.getSelectedIndex() != 0 && cbocurso.getSelectedIndex() != -1) {
            this.generarModelo();
           // c.listaMateriaAsignada(this.cboasignatura, this.cbocurso.getSelectedItem().toString());
            c.listaAlumnoCurso(tblasistencias, modelo, cbocurso.getSelectedItem().toString());
            this.formatearTabla();
          //  getDocente();
        }
    }//GEN-LAST:event_cbocursoActionPerformed

    private void btnimportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnimportarActionPerformed
         JFileChooser jf = new JFileChooser();

        FileNameExtensionFilter filtro = new FileNameExtensionFilter("xls", "xlsx");
        jf.setFileFilter(filtro);
        jf.showOpenDialog(null);

        Excel xls = new Excel(jf.getSelectedFile().getAbsolutePath());
        //  System.out.println(modelo.getRowCount());   

        xls.leerAsistencias(modelo);

    }//GEN-LAST:event_btnimportarActionPerformed

    private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed
        if (cbocurso.getSelectedIndex() == 0 )// & 
        {
            global.Dialogos.FaltaCampo("Curso");
            return;
        }


        if (cboparcial.getSelectedIndex() == 0 ) {
            global.Dialogos.FaltaCampo("Parcial");
            return;
        }

        if (cboquimestre.getSelectedIndex() == 0 ) {
            global.Dialogos.FaltaCampo("Quimestre");
            return;
        }
        Notas n=new Notas();
        n.setParcial(cboparcial.getSelectedItem().toString());
        n.setQuimestre(cboquimestre.getSelectedItem().toString()); 
        n.insertarInasistencia(modelo); 
    }//GEN-LAST:event_btnguardarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmasistencias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmasistencias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmasistencias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmasistencias.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                frmasistencias dialog = new frmasistencias(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnguardar;
    private javax.swing.JButton btnimportar;
    private javax.swing.JButton btnnuevo;
    private javax.swing.JButton btnsalir;
    private javax.swing.JComboBox cbocurso;
    private javax.swing.JComboBox cboparcial;
    private javax.swing.JComboBox cboquimestre;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTable tblasistencias;
    // End of variables declaration//GEN-END:variables
}
